using UnityEngine;
using System.Collections;

public class PlayerAnim : MonoBehaviour {
	
	public int tileX,tileY;	
	public float AnimRate;
	
	private float tileWidth,tileHeight;
	private float animTimer;
	private int animIndex;
	
	
	
	
	
	
	void Start(){
		//TurnRight();
		tileWidth = 1.0f/tileX;
		tileHeight = 1.0f/tileY;		
		renderer.material.mainTextureScale = new Vector2(tileWidth,tileHeight);
	}
	
	void Update(){
		if(Time.timeSinceLevelLoad-animTimer>AnimRate ){
			
			animTimer = Time.timeSinceLevelLoad;
			animIndex = (animIndex+1)%4;
			
			renderer.material.mainTextureOffset = new Vector2(animIndex*tileWidth,(int)PlayerCtrl.g_MoveState*tileHeight);
			
			
		}		
	}
	
}
